package com.usefullc.blog.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.blog.domain.ArticleRead;
import com.usefullc.blog.mapper.ArticleReadMapper;
import com.usefullc.blog.query.ArticleReadQuery;
import com.usefullc.blog.vo.ArticleReadVo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 文章阅读服务类
 * @author: 星空
 * @date: 2022-07-12
 */
@Service
public class ArticleReadService extends AbstractBizService<ArticleReadMapper, ArticleRead, ArticleReadQuery> {


    @Override
    protected QueryWrapper<ArticleRead> getQueryWrapper(ArticleReadQuery query) {
        QueryWrapper<ArticleRead> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }

    public Pager<ArticleReadVo> findVoByPage(ArticleReadQuery query){
        Pager<ArticleRead> page = this.findByPage(query);
        Pager<ArticleReadVo> newPage = new Pager<>(page);
        List<ArticleRead> dataList = page.getDataList();
        List<ArticleReadVo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (ArticleRead articleRead : dataList) {
            ArticleReadVo articleReadVo = BeanUtils.beanCopy(articleRead, ArticleReadVo.class);
            newDataList.add(articleReadVo);
        }
        return newPage;
    }


}
